package com.wuzheng.wisgo.sanitation.framework.base.pagination;

import com.baomidou.mybatisplus.plugins.Page;
import com.wuzheng.wisgo.sanitation.framework.util.StringUtils;
import io.swagger.annotations.ApiModelProperty;

/**
 * @author：hibon
 * @date：Created in 2019/08/16
 * @description：
 * @modified By：
 * @version: 1.0
 */
public class Pagination {

    /**
     * 升序
     */
    public final static String ASC = "asc";
    /**
     * 降序
     */
    public final static String DESC = "desc";

    @ApiModelProperty("每页数据条数")
    private Integer size;
    @ApiModelProperty("分页页码")
    private Integer current;
    @ApiModelProperty("排序字段")
    private String orderBy;
    @ApiModelProperty("排序顺序")
    private String orderDirection ;

    public <T> Page getPage() {
        Integer pageSize = this.size != null ? this.size : 20;
        Integer pageNumber = this.current != null ? this.current : 1;
        Page<T> page = new Page<T>(pageNumber, pageSize);
        if (StringUtils.isNotEmpty(orderBy)) {
            page.setOpenSort(true);
            page.setOrderByField(orderBy);
            page.setAsc(!DESC.equals(orderDirection));
        }
        return page;
    }

    public Integer getSize() {
        return size;
    }

    public void setSize(Integer size) {
        this.size = size;
    }

    public Integer getCurrent() {
        return current;
    }

    public void setCurrent(Integer current) {
        this.current = current;
    }

    public String getOrderBy() {
        return orderBy;
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }

    public String getOrderDirection() {
        return orderDirection;
    }

    public void setOrderDirection(String orderDirection) {
        this.orderDirection = orderDirection;
    }
}
